package com.ease.integration.service.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ease.integration.context.vo.IntegrationServiceContext;
import com.ease.integration.message.ResponseMessage;
import com.ease.integration.service.AbstractIntegrationExternalService;
import com.ease.integration.service.ExternalServiceDispatcherWrapper;

public abstract class AbstractIntegrationExternalServiceImpl implements AbstractIntegrationExternalService {

	private static final transient Log log = LogFactory.getLog(AbstractIntegrationExternalServiceImpl.class);

	// 对发往外部的请求进行统一分派
	private ExternalServiceDispatcherWrapper externalServiceDispatcherWrapper;

	protected ResponseMessage invoke(IntegrationServiceContext integrationServiceContext) {
		try {
			integrationServiceContext = externalServiceDispatcherWrapper.doService(integrationServiceContext);
			return integrationServiceContext.getResponseMessage();
		} catch (Exception e) {
			log.error(e, e);
			return null;
		}
	}

	/*
	 * private ResponseMessage convertToLocalClass(Object obj) { Object message = null; try { message =
	 * Class.forName(obj.getClass().getName()).newInstance(); BeanUtils.copyProperties(obj, message); return
	 * (ResponseMessage)message; } catch (Exception e) { log.error(e, e); return null; }
	 * 
	 * }
	 */

	public ExternalServiceDispatcherWrapper getExternalServiceDispatcherWrapper() {
		return externalServiceDispatcherWrapper;
	}

	public void setExternalServiceDispatcherWrapper(ExternalServiceDispatcherWrapper externalServiceDispatcherWrapper) {
		this.externalServiceDispatcherWrapper = externalServiceDispatcherWrapper;
	}

}
